package com.hibernate.model_extends;



import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.hibernate.dao.HibernateSessionFactory;
import org.hibernate.Transaction;

import com.hibernate.model.BasicinfoDAO;



public class Get_unread {
	
	
    public int getUnread(String userid)
    {  int num=0;
       Transaction se;
       List te=null;
       List de=null;
       try{
   		se= HibernateSessionFactory.getSession().beginTransaction();
    		String pbnews="select pb from Basicinfo bs , Pubbox pb where bs.id=? AND bs.newsTime<pb.time ";
    		String prnews="select us from  Usernews us where us.userid=? AND us.rdState='n' ";
   		te=HibernateSessionFactory.getSession().createQuery(pbnews)
   		.setParameter(0,userid)
   		.list();
   		
   		de=HibernateSessionFactory.getSession().createQuery(prnews)
   		   	.setParameter(0,userid)
   		   		.list();
   			 se.commit();
   		 
   	 }catch( Exception e){
   		 HibernateSessionFactory.getSession().getTransaction().rollback();
   	 }
   	 finally {
   		 HibernateSessionFactory.closeSession();
   	 }
    if(te!=null)
    	num +=te.size();
    if(de!=null)
    	num+=de.size();
  //  System.out.println(te+""+de);
       return num;
    }
    
  public static void main(String []a ){
	   Get_unread dd=new Get_unread();
	   System.out.println(dd.getUnread("102011132")+""+1/3);
	   
	   
   }
}
